package com.training.collection.section9;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class HashMapDemo {

	public static void main(String[] args) {
		Map<String,Integer> map = new HashMap<>();
		
		map.put("a", 1);
		map.put("b", 2);
		map.put("c", 3);
		map.put("d", 4);
		System.out.println(map);
		
		map.remove("b");
		System.out.println(map);
		
		map.put("a", 99);
		System.out.println(map);
		
		System.out.println(map.get("a"));

		//keyset
		System.out.println("------keyset-------");
		Set<String> set=map.keySet();
		for(String key:set) {
			System.out.println(key+":"+map.get(key));
		}
		
		System.out.println("------values-------");
		Collection<Integer> values = map.values();
		for(int t:values) {
			System.out.println(t);
		}
		
		System.out.println("------entrySet-------");
		Set<Entry<String,Integer>>set2 = map.entrySet();
		Iterator<Entry<String,Integer>>it = set2.iterator();
		
		while(it.hasNext()) {
			Entry<String,Integer> entry = it.next();
			System.out.println(entry.getKey()+":"+entry.getValue());
		}
	}

}
